<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <title>锁屏页面</title>

    <!-- CSS -->
    <link rel="stylesheet" th:href="@{static/plugins/layui/css/layui.css}"/>
    <link rel="stylesheet" th:href="@{static/mycss/common.css}"/>

</head>
<body>

    <form class="layui-form" id="formId">
        <div class="lockPageBox">
            <div class="lockPageDiv">
                <div class="lockPageDiv_1">
                    <div th:if="${sysAcc != null}">
                        <img th:src="@{/sysAcc/getPhoto(filePath=${sysAcc.sa02})}"/>
                    </div>
                    <div th:if="${sysAcc == null}">
                        <img th:src="@{static/images/head/head.jpg}"/>
                    </div>
                    <input type="hidden" name="id" id="id"/>
                    <p><span id="name"></span></p>
                </div>
                <div class="lockPageDiv_2">
                    <input type="password" class="layui-input" name="password" id="password" placeholder="请输入密码解锁.."/>
                    <button class="layui-btn" id="unlock" lay-submit="" lay-filter="unlockFilter">解锁</button>
                </div>
            </div>
        </div>
    </form>

<!-- JS -->
<script type="text/javascript" th:src="@{static/plugins/layui/layui.js}"></script>

<script>

    var userInfo = sessionStorage.getItem("userInfo");

    layui.use(['form', 'layer'], function () {
        var $ = layui.$;
        var form = layui.form;
        var layer = layui.layer;

        $('#name').text(JSON.parse(userInfo).su01);
        $('#id').val(JSON.parse(userInfo).su00);

        /**
         * 解锁
         */
        form.on('submit(unlockFilter)', function (data) {
            var subInfo;//提交信息
            //表单验证
            if($("#password").val() === ""){
                layer.msg('请输入解锁密码',{icon:5,time:1000});
                return false;
            }else {
                $.ajax({
                    url: 'sysUser/doUnlock',
                    type: 'post',
                    data: {jsonStr: JSON.stringify(data.field)},
                    dataType: 'json',
                    success: function (data) {
                        if(data.code === 0){
                            sessionStorage.setItem("pageLocked", false);
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }else{
                            layer.msg("密码不正确", {icon: 5, time: 1500});
                            $('#password').focus();
                        }
                    }
                });
            }
            //注：此处必须有这个，因为这里我用了自己的ajax来提交表单，如果不return false，form监听程序本身也会触发提交，可能会出现莫名奇妙的错误
            return false;
        });

        /**
         * 绑定 Enter 键
         */
        $(document).on('keydown', function() {
            //绑定 Enter键
            if(event.keyCode == 13) {
                $("#unlock").click();
            }
        });

    });
</script>

</body>
</html>